package lesson20;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class MyFutureTask {

    public static void main(String[] args) {
        FutureTask futureTask = new FutureTask<>(new Task());
        new Thread(futureTask).start();
        try {
            System.out.println(futureTask.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

    }

    static class Task implements Callable<Integer>{
        @Override
        public Integer call() throws Exception {
            System.out.println("子线程正在计算....");
            int sum = 0;
            for(int i = 0; i < 100; i++){
                sum += i;
            }
            return  sum;
        }
    }
}
